package com.fqxiny.lease.web.app.controller.history;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fqxiny.lease.common.result.Result;
import com.fqxiny.lease.common.utils.JWTUtil;
import com.fqxiny.lease.web.app.service.BrowsingHistoryService;
import com.fqxiny.lease.web.app.vo.history.HistoryItemVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.jsonwebtoken.Claims;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "浏览历史管理")
@RequestMapping("/app/history")
public class BrowsingHistoryController {
    @Autowired
    private BrowsingHistoryService service;

    @Operation(summary = "获取浏览历史")
    @GetMapping("pageItem")
    private Result<IPage<HistoryItemVo>> page(@RequestParam long current, @RequestParam long size,
                                              @RequestHeader("access_token" )String token) {
        IPage<HistoryItemVo> page = new Page<>(current, size);
        Claims claims = JWTUtil.parseToken(token);
        Long userId = claims.get("userId", Long.class);
        IPage<HistoryItemVo> list = service.pageHistoryItemByUserId(page, userId);
        return Result.ok(list);
    }

}
